<template>
	<view class="cart-box" v-if="cart.length">
		<my-address></my-address>
		<view class="cart-title">
			<uni-icons type="shop" size="18"></uni-icons>
			<text class="cart-title-text">购物车</text>
		</view>
		<uni-swipe-action>
			<block v-for="(goods, i) in cart" :key="i">
				<uni-swipe-action-item :right-options="options" @click="cancelClick(goods)">
					<my-goods :goods="goods" :show-radio="true" :show-num="true" @radio-change="radioChangeHandler" @num-change="numChangeHandler"></my-goods>
				</uni-swipe-action-item>
			</block>
		</uni-swipe-action>
		<my-settle></my-settle>
	</view>
	<view class="empty-cart" v-else>
		<image src="/static/cart_empty@2x.png" class="empty-img"></image>
		<text class="empty-tip">空空如也~</text>
	</view>
</template>

<script>
	import {mapState, mapMutations} from 'vuex';
	import badgeMix from '@/mixins/tabbar-badge.js';
	
	export default {
		mixins: [badgeMix],
		data() {
			return {
				//右侧选项内容及样式
				options: [
					{
						text: '删除',
						style: {
								backgroundColor: '#C00000'
						}
					},
				],
			};
		},
		computed: {
			...mapState('m_cart', ['cart']),
		},
		methods: {
			...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount', 'removeGoodsById']),
			//复选框状态改变
			radioChangeHandler(e){
				this.updateGoodsState(e);
			},
			//商品数量改变
			numChangeHandler(e){
				this.updateGoodsCount(e);
			},
			//点击删除按钮
			cancelClick(goods){
				this.removeGoodsById(goods.goods_id);
			},
		},
	}
</script>

<style lang="scss">
.cart-box {
	padding-bottom: 50px;
	.cart-title {
		height: 40px;
		padding-left: 5px;
		display: flex;
		align-items: center;
		border-bottom: solid 1px #EFEFEF;
		.cart-title-text {
			margin-left: 10px;
			font-size: 14px;
		}
	}
}
.empty-cart {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding-top: 150px;
	.empty-img {
		width: 90px;
		height: 90px;
	}
	.empty-tip {
		color: gray;
		font-size: 12px;
		margin-top: 15px;
	}
}
</style>
